﻿
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.FlowElementGrid = function (config) {

    Ext.apply(this, config);

    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '../Service/FlowElementViewService.aspx?Action=Search'

        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Name', 'Description', 'FlowFlie', 'Organization', 'Details', 'Equip', 'Require', 'PersonNumber', 'EchelonNumber']
        }),
        remoteStore: true
    });

    this.store = fileStore;

    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        noSort: true,
        defaultNum: 21
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    }, {
        header: '参与部门',
        dataIndex: 'Organization',
        width: 100,
        sortable: true
    }, {
        header: '人数',
        dataIndex: 'PersonNumber',
        width: 100,
        sortable: true

    }, {
        header: '梯队',
        dataIndex: 'EchelonNumber',
        width: 100,
        sortable: true

    },{
        header: '任务',
        dataIndex: 'Details',
        width: 100,
        sortable: true,
        renderer: function qtips(val, p, record) {
            return '<span style="display:table;width=100%;" qtip=\'<div>' + val + '</div>\'>任务</span>'
        }

    }];
    FantastPlatform.UI.FlowElementGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
}

Ext.extend(FantastPlatform.UI.FlowElementGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.FlowElementGrid.superclass.onRender.call(this, ct, position);
    },
    onAddFlowElementClick: function (flowId,level) {
        var id = GUID();
        currtWind = openWind('../EmergencyFlow/FlowElementForm.aspx?flowId=' + flowId + '&level=' + level, id, '新增警力分配', 650, 400, null);
    },
    //删除
    onDeleteClick: function () {
        var grid = this;
        var node = checkGridSelected(this);
        if (node) {
            Ext.Msg.confirm('提示', '确认要删除选中的数据吗？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在删除数据，请稍候……', '删除数据');
                    var fIds = getIdFromGrid(node, 'Id');
                    ajaxCalled(null, '../Service/FlowElementViewService.aspx?Action=Delete', fIds, grid, null);
                }

            })
        }
    },
    //修改
    onEditFlowElementClick: function () {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
              //  if (node[0].get('PoliceMan') == policemanNumber) {
                    var fId = node[0].get('Id');
                    var id = GUID();

                    currtWind = openWind('../EmergencyFlow/FlowElementForm.aspx?id=' + fId, id, '编辑警力分配', 650, 400, null);
             //   } else {
             //       showErrorMessage("操作失败", "只能自己添加的数据进行编辑", "");          
              //  } 
            }
        }
    },
        onSearchClick: function (flowId,flowLevelId) {
        var id = GUID();
        currtWind = openWind('../EmergencyFlow/FlowElementSearchForm.aspx?Id=' + flowLevelId + "&flowId=" + flowId, id, '查询', 360, 170, 'new_tab');
    }
    ,     
    //刷新
    onUpdataFlowElementClick: function (level) {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: this.url };
        this.store.load({ params: {level:level, start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }

});
    
